<? include 'server_config.php'; 

if($_SESSION['user_idx'] == "")
{
	?>
	<script>
		location.href='login.php';
	</script>
	<?
	return;
}

?>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<?

$path = "./upload/member_photo/";
$uploaded_name = $_SESSION['user_idx'];

if($img_changed=='1')
{
	copy($path.$uploaded_name."_temp",$path.$uploaded_name);

}


/*
$path = "./upload/member_photo/";

$att = "member_photo";

if ($_FILES[$att]["error"] > 0 || $_FILES[$att]["size"]==0)
  {
	//	  echo "Error: " . $_FILES[$att]["error"] . "<br />";
  }
else
  {
	$uploaded_name = $_SESSION['user_idx'];

  echo move_uploaded_file($_FILES[$att]["tmp_name"],
  $path.$uploaded_name);

  }

*/


	$sql = "
	UPDATE ndd_user SET nickname = '$member_nickname', region_1 = '$wr_sido', region_2 = '$wr_gugun'
	WHERE user_idx = '$user_idx'
	";
	$result = mysql_query($sql,$connect);

	$sql = "
	UPDATE ndd_user_expand SET sex = '$member_sex', birthday = '$member_birth', introduce = '$member_introduce'
	WHERE user_idx = '$user_idx'
	";
	$result = mysql_query($sql,$connect);

/*
if ($document_idx=="")
{
	$sql = "
	INSERT INTO ndd_document
	VALUES
	(
	'', '$board_idx', '$user_idx', '$category_idx', '$title', '$content',
	0, 0, 0, 0, '".$_SESSION['user_idx']."', CURRENT_TIMESTAMP, CURRENT_TIMESTAMP);
	";

	//echo $sql;
	$result = mysql_query($sql,$connect);


	$sql = "
	SELECT MAX(document_idx) FROM ndd_document
	WHERE board_idx = '$board_idx'
	AND user_idx = '$user_idx'
	AND category_idx = '$category_idx'
	";
	$result = mysql_query($sql,$connect);
	$row = mysql_fetch_row($result);

	$document_idx = $row[0];


}
else
{

	$sql = "
	SELECT user_idx FROM ndd_document
	WHERE document_idx = '$document_idx'
	";
	$result = mysql_query($sql,$connect);
	$row = mysql_fetch_row($result);

	$document_user_idx = $row[0];

	if ($_SESSION['user_idx']==$document_user_idx)
	{
		$sql = "UPDATE ndd_document SET title = '$title', content='$content', modify_timestamp = CURRENT_TIMESTAMP
		WHERE document_idx= '$document_idx' ;  ";

		$result = mysql_query($sql,$connect);

	}

}



	$path = "./upload/";

	for($i=1;$i<=5;$i++)
	{
		$att = "attachfile_".$i;

		if ($_FILES[$att]["error"] > 0 || $_FILES[$att]["size"]==0)
		  {
//		  echo "Error: " . $_FILES[$att]["error"] . "<br />";
		  }
		else
		  {
		  echo "Upload: " . $_FILES[$att]["name"] . "<br />";
		  echo "Type: " . $_FILES[$att]["type"] . "<br />";
		  echo "Size: " . ($_FILES[$att]["size"] / 1024) . " Kb<br />";
		  echo "Stored in: " . $_FILES[$att]["tmp_name"]."<br>";

		
			$sql2="SELECT MAX(file_idx) FROM ndd_file;";
			$result2 = mysql_query($sql2,$connect);
			$row2 = mysql_fetch_row($result2);
			$new_file_idx = $row2[0]+1;

			$uploaded_name = "b_".$document_idx."_".$new_file_idx;

		  echo move_uploaded_file($_FILES[$att]["tmp_name"],
		  $path.$uploaded_name);

			$sql2="
				INSERT INTO ndd_file 
				VALUES ('', '$document_idx', '$uploaded_name', '".$_FILES[$att]['name']."', 0, ".($_FILES[$att]["size"] / 1024).");";
			$result2 = mysql_query($sql2,$connect);

		  }

	}


*/






?>

<script> 
location.href="ndd_member_info.php";
</script>











